package com.entrogy.service.impl;

import com.entrogy.bean.MenuEntity;
import com.entrogy.dao.MenuMapper;
import com.entrogy.bean.UserEntity;
import com.entrogy.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<MenuEntity> getMenuByUserId(String userId, int schoolCode) {
        return menuMapper.getMenuitemByUserId(userId, schoolCode);

    }

    @Override
    public List<MenuEntity> findMenusByRoleId(Integer roleId) {
        List<MenuEntity> parentMenuEntities = menuMapper.findParentMenusByRoleId(roleId);
        for (int i = 0; i < parentMenuEntities.size(); i++){
            List<MenuEntity> childMenuEntities = menuMapper.findChildMenusByParentId(parentMenuEntities.get(i).getMenuId(), roleId);
            parentMenuEntities.get(i).setMenuEntities(childMenuEntities);
        }
        return parentMenuEntities;

    }
}
